# 变量
var = 'hhhhh'  # -->  1 开辟 内存空间,'hhhhh' 2 开辟变量的内存空间   3 将左边的变量指向右边实际数据的内存地址
print(var)

# 标识符  : 变量 函数名 类名
# 变量来说: 只能用 字母数字下划线, 并且不能以数字开头

# 基本数据类型

# int  整型  整数  3  +-*/
# float 1.2 科学计数法
# bool  True Flase
# str 字符串

print(2 / 3)  # 真除
print(5 // 3)  # 经典除法 将小数部分舍去,直接得到整数部分
print(type(4))
print(type(4.1))
print(type(2e3))
print(2e3)

print(type(True))
print(type(False))

print(type('jjjjsasa'))
print(type('123'))
print(type('True'))

# 字符串的操作
a = 'zabcdefzhhzmmmmm'
b = '     sssfghewye   '
print(len(a))
print(a[0])
print(a.split('z'))
print(a.index('ab'))  # 返回给你index

# print(a.index('abfff'))  # 返回给你index  ValueError: substring not found
print(a.find('ab'))
print(a.find('abfff'))  # -1 ,而不会抛异常

print(a.startswith('abc'))
print(a.startswith('zabc'))
print(a.endswith('zabc'))

print(b)
print(b.strip())  # 将字符串两端的空白字符去掉
print(b.lstrip())
print(b.rstrip())

c = '***hhhhh****'
print(c)
print(c.strip('*'))

print(a.upper())
a = 'HHHHabckkk'
print(a.lower())
print(a.replace('kkk', '*****'))

a = 'abcdefghijklmn'
# 切片
print(a[1:3])  # index [)
print(a[1:5])  # index [)
print(a[1:5:2])  # start end step

print(a[:5])
print(a[5:])
print(a[:])

print(a[:-1])
print(a[::-1])  # nmlkjihgfedcba

# print(a[:3:-1]) --> nmlkjihgfe


# 数据结构  一个容器  高级一点的数据类型
# list  列表
# tuple 元组
# set 集合
# dict 字典

# 增删改查
print('*' * 20)
list1 = [1, 2, 'strsfdsaf', 'hh', 'hh', 'hh']
print(type(list1))  # <class 'list'>

print(list1[1])
print(list1[2])
print(len(list1))  # 元素的个数

list1.append('abc')
print(list1)

# 改  先得到,再赋值
list1[0] = 100
print(list1)

# 删除
# list1.remove(2)
# list1.remove(list1[0])
# del list1[0]

print(list1)

# pop
print(list1.pop())
print(list1)
print(list1.pop())
print(list1.pop())
print(list1.pop())
print(list1.pop())
# print(list1.pop()) # IndexError: pop from empty list
print(list1)

# -------tuple--------------
# 不可以被修改,其他和list一样

tuple1 = (1, 2, 'strsfdsaf', 'hh', 'hh', 'hh')
print(type(tuple1))  # <class 'tuple'>
print(tuple1[0])
# tuple1[0] =100  #TypeError: 'tuple' object does not support item assignment

# -----------set--------------

set1 = set()
print(type(set1))
print(set1)

set1.add('abc')
set1.add('kkk')
set1.add('kkk')
set1.add('bcd')
print(set1)

# 去重 无序
#  set  中的元素是不能重复的 ,并且元素的添加顺序和打印出来的顺序不一致


# dict  字典 key value  键值对

dict1 = {}
print(type(dict1))  # <class 'dict'>

# key  是不可变数据类型
# value 任意
dict1['abc'] = 89
dict1['zhangsan'] = 89
dict1[3] = 9999
dict1[(3, 4)] = 4

dict1['zhangsan'] = 99

# key 去重,覆盖(修改)
print(dict1)

# 修改
dict1['abc'] = 100
print(dict1)

# print(dict1.pop('abc'))
# print(dict1)

# 得到key值
print(dict1['abc'])
print(dict1.get('abc'))
# 当key不存在的时候
# print(dict1['abcd']) # KeyError: 'abcd'
print(dict1.get('abcd'))  # None

# 一次性得到容器中的所有元素
# 遍历容器

# for var in dict1.values():
for var in dict1.items():
    # print(dict1[var])
    print(var)

# 拆包 , unpack
a, b = (3, 9999)
print(a)
print(b)
# 很python风格的赋值方式
a, b = 3, 9999
print(a)
print(b)

# for items in dict1.items():
#     # print(items)
#     key, value = items
#     print('key:',key)
#     print(value)

for key, value in dict1.items():
    # key, value = items
    print('key:', key)
    print(value)

print('以下是遍历容器')
# var 代表的是 容器中的元素
# for var in tuple1:
# for var in list1:
for var in set1:
    print(var)

    #           list        tuple      set     dict
    # 是否去重  不去重     不去重     去重     key去重
    #                             打印顺序无序
    #            []         ()         set{}          {}
